<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Find Unicode character by name and return its code point value</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="intlchar.chardirection.html">« IntlChar::charDirection</a></li>
      <li style="float: right;"><a href="intlchar.charmirror.html">IntlChar::charMirror »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.intlchar.html">IntlChar</a></li>
    <li>Find Unicode character by name and return its code point value</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="intlchar.charfromname" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">IntlChar::charFromName</h1>
  <p class="verinfo">(PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">IntlChar::charFromName</span> &mdash; <span class="dc-title">Find Unicode character by name and return its code point value</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-intlchar.charfromname-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><strong>IntlChar::charFromName</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$name</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$type</code><span class="initializer"> = IntlChar::UNICODE_CHAR_NAME</span></span>): <span class="type"><span class="type">?</span><span class="type">int</span></span></div>

  <p class="para rdfs-comment">
   Finds a Unicode character by its name and returns its code point value.
  </p>
  <p class="para">
   The name is matched exactly and completely. If the name does not correspond to a code point, <strong><code>null</code></strong> is returned.
  </p>
  <p class="para">
   A Unicode 1.0 name is matched only if it differs from the modern name. Unicode names are all uppercase.
   Extended names are lowercase followed by an uppercase hexadecimal number, and within angle brackets.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-intlchar.charfromname-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">name</code></dt>

    <dd>

     <p class="para">
      Full name of the Unicode character.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">type</code></dt>

    <dd>

     <p class="para">
      Which set of names to use for the lookup. Can be any of these constants:
      <ul class="simplelist">
       <li class="member"><strong><code>IntlChar::UNICODE_CHAR_NAME</code></strong> (default)</li>
       <li class="member"><strong><code>IntlChar::UNICODE_10_CHAR_NAME</code></strong></li>
       <li class="member"><strong><code>IntlChar::EXTENDED_CHAR_NAME</code></strong></li>
       <li class="member"><strong><code>IntlChar::CHAR_NAME_ALIAS</code></strong></li>
       <li class="member"><strong><code>IntlChar::CHAR_NAME_CHOICE_COUNT</code></strong></li>
      </ul>
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-intlchar.charfromname-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   The Unicode value of the code point with the given name (as an <span class="type">int</span>), or <strong><code>null</code></strong> if there is no such code point.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-intlchar.charfromname-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-2492">
   <p><strong>示例 #1 Testing different code points</strong></p>
   <div class="example-contents">
    <div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">IntlChar</span><span style="color: #007700">::</span><span style="color: #0000BB">charFromName</span><span style="color: #007700">(</span><span style="color: #DD0000">"LATIN&nbsp;CAPITAL&nbsp;LETTER&nbsp;A"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">IntlChar</span><span style="color: #007700">::</span><span style="color: #0000BB">charFromName</span><span style="color: #007700">(</span><span style="color: #DD0000">"SNOWMAN"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">IntlChar</span><span style="color: #007700">::</span><span style="color: #0000BB">charFromName</span><span style="color: #007700">(</span><span style="color: #DD0000">"RECYCLING&nbsp;SYMBOL&nbsp;FOR&nbsp;TYPE-1&nbsp;PLASTICS"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">IntlChar</span><span style="color: #007700">::</span><span style="color: #0000BB">charFromName</span><span style="color: #007700">(</span><span style="color: #DD0000">"A&nbsp;RANDOM&nbsp;STRING&nbsp;WHICH&nbsp;DOESN'T&nbsp;CORRESPOND&nbsp;TO&nbsp;ANY&nbsp;UNICODE&nbsp;CHARACTER"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程会输出：</p></div>
   <div class="example-contents screen">
    <div class="cdata"><pre>
int(65)
int(9731)
int(9843)
NULL
</pre></div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-intlchar.charfromname-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="intlchar.charname.html" class="function" rel="rdfs-seeAlso">IntlChar::charName()</a> - Retrieve the name of a Unicode character</span></li>
    <li class="member"><span class="function"><a href="intlchar.enumcharnames.html" class="function" rel="rdfs-seeAlso">IntlChar::enumCharNames()</a> - Enumerate all assigned Unicode characters within a range</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>